﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DelonixRegiaHMSys.Core.Services;
using DelonixRegiaHMSys.Infrastructure.Data;

namespace DelonixRegiaHMSys.UI.WebForms
{
    public partial class StaffManagement : System.Web.UI.Page
    {
        string userID;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                userID = Request.QueryString["UserID"];
                BindGridView();
            }
        }

        private void BindGridView()
        {
            var sservice = new stServices(new EfStaffQuery());
            GridViewS.DataSource = sservice.GetAll().ToList();
            GridViewS.DataBind();
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            string staffID = (((LinkButton)sender).CommandArgument);
            var sservice = new stServices(new EfStaffQuery());
            sservice.DeleteStaff(staffID);
            BindGridView();
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            string[] arg = new string[9];
            arg = ((LinkButton)sender).CommandArgument.ToString().Split(';');
            string staffID = arg[0];
            string staffImage = arg[1];
            string staffLastName = arg[2];
            string staffFirstName = arg[3];
            DateTime DOB = Convert.ToDateTime(arg[4]);
            string bankAccNum = arg[5];
            string homeAddress = arg[6];
            string phoneNum = arg[7];
            string dutiesName = arg[8];

            string querystring = "UserID=" + userID + "&Staff=" + staffID + "&StaffImage=" + staffImage + "&StaffLastName=" + staffLastName + 
                "&StaffFirstName=" + staffFirstName + "&DOB=" + DOB + "&BankAccNum=" + bankAccNum + "HomeAdd=" + homeAddress + "&PhoneNum=" + phoneNum + 
                "DutiesName=" + dutiesName;
            Server.Transfer("~/WebForms/HousekeepingandStaffModule/UpdateStaff.aspx?" + querystring);
        }

        protected void lsbtn_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForms/HousekeepingandStaffModule/AssignSchedule.aspx?UserID=" + userID);
        }

        protected void addStafflbtn_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForms/HousekeepingandStaffModule/AddStaff.aspx?UserID=" + userID);
        }

        protected void btnback_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/Webforms/SystemAccountModule/Administrator.aspx?UserID=" + userID);
        }
    }
}